// 获取景点列表
const getAttractionsList = async (page = 1, limit = 10, keyword = '', category = '') => {
  // 模拟从数据库获取景点数据
  const attractions = [
    { id: 1, name: '景点A', description: '描述A', location: '地点A', image: 'URLA', category: '文化', rating: 4.5 },
    { id: 2, name: '景点B', description: '描述B', location: '地点B', image: 'URLB', category: '自然', rating: 4.0 },
    // ... 更多景点数据 ...
  ];

  // 模拟分页和搜索
  const filteredAttractions = attractions.filter(attraction =>
      attraction.name.includes(keyword) && attraction.category.includes(category)
  );

  const total = filteredAttractions.length;
  const startIndex = (page - 1) * limit;
  const endIndex = startIndex + limit;
  const paginatedAttractions = filteredAttractions.slice(startIndex, endIndex);

  return {
    total,
    page,
    list: paginatedAttractions
  };
};

// 获取景点详情
const getAttractionById = async (id) => {
  // 模拟从数据库获取景点数据
  const attractions = [
    { id: 1, name: '景点A', description: '描述A', location: '地点A', image: 'URLA', category: '文化', rating: 4.5, comments: [] },
    { id: 2, name: '景点B', description: '描述B', location: '地点B', image: 'URLB', category: '自然', rating: 4.0, comments: [] },
    // ... 更多景点数据 ...
  ];

  return attractions.find(attraction => attraction.id === parseInt(id));
};

// 添加新景点
const addAttraction = async (attractionData) => {
  // 模拟向数据库添加景点数据
  const newAttraction = {
    id: Date.now(),
    ...attractionData,
    rating: attractionData.rating || 0,
    comments: []
  };

  // 假设景点数据存储在一个数组中
  const attractions = [
    { id: 1, name: '景点A', description: '描述A', location: '地点A', image: 'URLA', category: '文化', rating: 4.5, comments: [] },
    { id: 2, name: '景点B', description: '描述B', location: '地点B', image: 'URLB', category: '自然', rating: 4.0, comments: [] },
    // ... 更多景点数据 ...
  ];

  attractions.push(newAttraction);

  return { id: newAttraction.id };
};

// 更新景点信息
const updateAttraction = async (id, updateData) => {
  // 模拟更新景点数据
  const attractions = [
    { id: 1, name: '景点A', description: '描述A', location: '地点A', image: 'URLA', category: '文化', rating: 4.5, comments: [] },
    { id: 2, name: '景点B', description: '描述B', location: '地点B', image: 'URLB', category: '自然', rating: 4.0, comments: [] },
    // ... 更多景点数据 ...
  ];

  const attraction = attractions.find(attraction => attraction.id === parseInt(id));
  if (attraction) {
    Object.assign(attraction, updateData);
  }
};

// 删除景点
const deleteAttraction = async (id) => {
  // 模拟删除景点数据
  const attractions = [
    { id: 1, name: '景点A', description: '描述A', location: '地点A', image: 'URLA', category: '文化', rating: 4.5, comments: [] },
    { id: 2, name: '景点B', description: '描述B', location: '地点B', image: 'URLB', category: '自然', rating: 4.0, comments: [] },
    // ... 更多景点数据 ...
  ];

  const index = attractions.findIndex(attraction => attraction.id === parseInt(id));
  if (index !== -1) {
    attractions.splice(index, 1);
  }
};

// 添加评论
const addComment = async (id, commentData) => {
  // 模拟向景点添加评论
  const attractions = [
    { id: 1, name: '景点A', description: '描述A', location: '地点A', image: 'URLA', category: '文化', rating: 4.5, comments: [] },
    { id: 2, name: '景点B', description: '描述B', location: '地点B', image: 'URLB', category: '自然', rating: 4.0, comments: [] },
    // ... 更多景点数据 ...
  ];

  const attraction = attractions.find(attraction => attraction.id === parseInt(id));
  if (attraction) {
    attraction.comments.push(commentData);
  }
};

// 获取景点评论
const getComments = async (id) => {
  // 模拟获取景点评论
  const attractions = [
    { id: 1, name: '景点A', description: '描述A', location: '地点A', image: 'URLA', category: '文化', rating: 4.5, comments: [{ user: '张三', content: '风景很好！', rating: 4.5 }] },
    { id: 2, name: '景点B', description: '描述B', location: '地点B', image: 'URLB', category: '自然', rating: 4.0, comments: [] },
    // ... 更多景点数据 ...
  ];

  const attraction = attractions.find(attraction => attraction.id === parseInt(id));
  return attraction ? attraction.comments : [];
};

module.exports = {
  getAttractionsList,
  getAttractionById,
  addAttraction,
  updateAttraction,
  deleteAttraction,
  addComment,
  getComments
};
